package com.liyiruo.tx.service.main15new;

import com.liyiruo.tx.mapper.TableBMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

/**
 * @author liyiruo
 * @Description
 * @Date 2024/4/9 下午2:30
 */
@Service(value = "testBe15")
public class TestBe {

    PlatformTransactionManager platfromTransactionManager;

    public TestBe(PlatformTransactionManager platfromTransactionManager) {
        this.platfromTransactionManager = platfromTransactionManager;
    }

    @Autowired
    private TableBMapper tableBMapper;


    public void testB() {

        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
        TransactionStatus transaction = platfromTransactionManager.getTransaction(def);
        //update
        tableBMapper.addTableB();
        int i = 1 / 0;
        tableBMapper.addTableB();
        platfromTransactionManager.commit(transaction);
        // platfromTransactionManager.rollback(transaction);

    }

}
